class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int l = 0, r = 0, ans = INT_MAX;
        int n = nums.size();
        for (int r = 0, sum = 0; r < n; r++)
        {
            sum += nums[r];
            while (sum - nums[l] >= target)
            {
                sum -= nums[l++];
            }
            if (sum >= target)
                ans = min(ans, r - l + 1);

        }
        return ans == INT_MAX ? 0 : ans;
    }
};